<!--#
layout("/layouts/store.html"){
#-->
<header class="header navbar bg-white shadow">
    <div class="btn-group tool-button">
        <a class="btn btn-primary navbar-btn" href="${base}/store/goods/goodsclass" data-pjax id="goback"><i class="ti-angle-left"></i> ${msg['globals.button.back']}</a>
    </div>
</header>

<div class="content-wrap">
    <div class="wrapper" style="min-height:500px;">
        <section class="panel panel-form">
            <form id="addForm" role="form" class="form-horizontal parsley-form" data-parsley-validate
                  action="${base}/store/goods/goodsclass/editDo" method="post">
                <input type="hidden" name="id" value="${obj.id!}">
                <input type="hidden" name="hasChildren" value="${obj.hasChildren!}">
                <div class="row mb10">
                    <div class="col-lg-12">
                        <div class="form-group has-feedback">
                            <label for="parentId" class="col-sm-2 control-label">${msg['globals.button.parentType']}</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="parentId" value="${isNotEmpty(pobj) ? pobj.name!}" placeholder="${msg['goods.class.column.ifDoesNotChoose']}" disabled />
                                <input type="hidden" name="parentId" value="${isNotEmpty(pobj) ? pobj.id!}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="name" class="col-sm-2 control-label">${msg['goods.class.column.name']}</label>
                            <div class="col-sm-8">
                                <input type="text" id="name" class="form-control" name="name" data-parsley-required="true" placeholder="${msg['goods.class.column.name']}" value="${obj.name!}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="name" class="col-sm-2 control-label">淘宝类目编号</label>
                            <div class="col-sm-8">
                                <input type="text" id="cId" class="form-control" name="cId"  placeholder="淘宝类目编号" value="${obj.cId!}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="imageUrl" class="col-sm-2 control-label">icon图片</label>
                            <div class="col-sm-6">
                                <div id="imgQueue"></div>
                                <div>
                                    <input id="file_upload_img" name="file_upload" type="file"
                                           multiple="false">
                                </div>
                                <div id="img" style="padding: 5px;">
                                    <img src='${obj.iconUrl}' style='width:150px;height:95px;'>
                                    <i class="fa fa-close" onclick="clearFile()"></i>
                                </div>
                                <input type="hidden" id="imageUrl" name="iconUrl" value="${obj.iconUrl}">
                            </div>
                            <div class="col-sm-2" style="color: red;">建议尺寸：145*100</div>
                        </div>
                        <div class="form-group">
                            <label for="disabled" class="col-sm-2 control-label">${msg['goods.class.column.disabled']}</label>
                            <div class="col-sm-8 switcha">
                                <div class="mr15">
                                    <input type="checkbox" id="disabled" name="disabled" <!--#if(obj.disabled){#-->checked<!--#}#--> class="js-switch-red">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-3"></div>
                <div class="col-lg-6">
                    <div class="form-group text-center">
                        <label></label>
                        <div>
                            <button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="${msg['globals.button.submit.tip']}">${msg['globals.button.submit']}</button>
                        </div>
                    </div>
                </div>
            </form>
        </section>
    </div>
</div>
<a class="exit-offscreen"></a>
<!-- 选择上级 -->
<div id="dialogSelectParent" class="modal fade bs-modal-sm" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">${msg['goods.class.column.chooseParent']}</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-xs-12">
                        <div id="jsTreeParent" class="demo"></div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <div class="pull-left">
                    <button type="button" class="btn btn-success" data-dismiss="modal" onclick="selectFirstMenu()">${msg['goods.class.column.changeTop']}</button>
                </div>
                <button type="button" class="btn btn-default" data-dismiss="modal">${msg['globals.button.cancel']}</button>
                <button type="button" class="btn btn-primary" onclick="selectParent()">${msg['goods.class.column.enter']}</button>
            </div>
        </div>
    </div>
</div>
<script language="JavaScript">
    $(document).ready(function () {
        myForm.init();
        $('#addForm').ajaxForm({
            dataType: 'json',
            beforeSubmit: function (arr, form, options) {
                form.find("button:submit").button("loading");
            },
            success: function (data, statusText, xhr, form) {
                if (data.code==0) {
                    Toast.success(data.msg);
                    setTimeout(function () {
                        $("#goback").trigger("click");
                    }, 1000);
                } else {
                    Toast.error(data.msg);
                }
                form.find("button:submit").button("reset");
            }
        });

        //上传图片
        $('#file_upload_img').uploadifive({
            'auto': true,
            'multi': false,
            'width': '100%',
            'height': '35',
            'buttonText': '选择图片',
            'fileType': 'image/jpg,image/jpeg,image/png',
            'fileSizeLimit': 2048,
            'queueSizeLimit': 1,
            'overrideEvents': ['onDialogClose', 'onError'],
            'formData': {},
            'queueID': 'imgQueue',
            'uploadScript': '${base}/open/file/upload/image',
            'onUploadComplete': function (file, data) {
                data = JSON.parse(data);
                if (data.code == 0) {
                    Toast.success(data.msg);
                    $("#img").html("<img src='" + data.data + "' style='width:150px;height:95px;'>");
                    $("#imageUrl").val(data.data);
                } else {
                    clearFile();
                    Toast.error(data.msg);
                }
            },
            'onDrop': function (file, fileDropCount) {
                clearFile();
            },
            'onClearQueue': function (queue) {
                clearFile();
            },
            'onError': function (errorType, file) {
                if (file != 0) {
                    // var settings = $("#" + fileuploadId).uploadifive().settings;
                    switch (errorType) {
                        case 'UPLOAD_LIMIT_EXCEEDED':
                            Toast.error("上传的文件数量已经超出系统限制的1个文件！");
                            break;
                        case 'FILE_SIZE_LIMIT_EXCEEDED':
                            Toast.error("文件大小超出系统限制的2M大小！");
                            break;
                        case 'FORBIDDEN_FILE_TYPE':
                            Toast.error("文件类型不正确！");
                            break;
                    }
                }
            },
            'onCancel': function () {
                clearFile();
            }
        });

    });


    /**
     * 上传图片
     */
    function clearFile() {
        $("#img").html("");
        $("#imgQueue").html("");
        $("#imageUrl").val("");
    }
</script>
<!--#}#-->